package com.zhao.kafka.mysql

import java.util.Properties

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}

/**
 * Description: Kafka生产者<br/>
 * Copyright (c) ，2020 ， 赵 <br/>
 * This program is protected by copyright laws. <br/>
 * Date： 2020/12/25 11:31
 *
 * @author 柒柒
 * @version : 1.0
 */

object KafkaProducerTest {
  def main(args: Array[String]): Unit = {
    val props: Properties = new Properties()
    props.put("bootstrap.servers",ConfigConstants.kafkaBrokers)
//    props.put("batch.size",ConfigConstants.batchSize)
//    props.put("linger.ms",ConfigConstants.lingerMs)
//    props.put("buffer.memory",ConfigConstants.bufferMemory)
    props.put("key.serializer",ConfigConstants.kafkaKeySer)
    props.put("value.serializer",ConfigConstants.kafkaValueSer)

    val producer: KafkaProducer[String, String] = new KafkaProducer[String, String](props)

    val startTime: Long = System.currentTimeMillis()
    for (i <- 1 to 1000){
      producer.send(new ProducerRecord[String,String](ConfigConstants.kafkaTopic,"spark",Integer.toString(i)))
    }
    println("消耗时间:"+(System.currentTimeMillis() - startTime))
    producer.close()
  }
}











